use crate::fasttime::b3_datetime::DateTimeFT;



#[derive(Debug)]
pub struct LogItem {
    pub id: u32,
    pub level: log::Level,
    pub time: DateTimeFT,
    pub message: String,
}



impl LogItem {
    pub fn to_print(&self) -> String {
        let Self { id, level, time, message } = self;
        format!("{id}: {message}【{}】{}.", super::level_cn(level), time.to_print_hmsi())
    }
}
impl LogItem {
    pub fn error(id: u32, message: String) -> Self {
        Self {
            id,
            level: log::Level::Error,
            time: DateTimeFT::now(),
            message,
        }
    }
    pub fn warn(id: u32, message: String) -> Self {
        Self {
            id,
            level: log::Level::Warn,
            time: DateTimeFT::now(),
            message,
        }
    }
    pub fn info(id: u32, message: String) -> Self {
        Self {
            id,
            level: log::Level::Info,
            time: DateTimeFT::now(),
            message,
        } 
    }
    pub fn debug(id: u32, message: String) -> Self {
        Self {
            id,
            level: log::Level::Debug,
            time: DateTimeFT::now(),
            message,
        }
    }
    pub fn trace(id: u32, message: String) -> Self {
        Self {
            id,
            level: log::Level::Trace,
            time: DateTimeFT::now(),
            message,
        }
    }
}

impl Default for LogItem {
    fn default() -> Self {
        Self {
            id: 0,
            level: log::Level::Info,
            time: DateTimeFT::now(),
            message: "".to_string(),
        }
    } 
}